/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.unittests;

import opiam.admin.faare.PropertiesManager;
import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.services.StandardService;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.log4j.Logger;


/**
 * This class is a model to create the test classes.
 */
public class TestTemplate extends TestCase
{
    /** Instance of logger. */
    private static Logger _logger = Logger.getLogger(TestTemplate.class);

    /** Instance of the trace class. */
    private static TestUtils _test = new TestUtils(_logger);

    /** Test user DN. */
    private static final String DN_USER = "uid=jreuter, ou=People, dc=mycompany,dc=com";

    /** Test user login. */
    private static final String LOGIN_USER = "jreuter"; //uid

    /** Test user password. */
    private static final String PASSWORD_USER = "destroy";

    /** User context. */
    private static UserContext _USERCONTEXT = new UserContext();

    /**
     * Creates a new TestTemplate object.
     *
     * @param param  Parameter.
     */
    public TestTemplate(String param)
    {
        super(param);

        try
        {
            PropertiesManager.getInstance();

            if (!_USERCONTEXT.isLoggedIn())
            {
                StandardService.logon(LOGIN_USER, PASSWORD_USER, _USERCONTEXT);
            }
        }
        catch (Exception e)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("TestTemplate constructor error");
            msg.append(TestUtils.NEXT);
            msg.append(e.toString());
            _test.displayResultError(msg.toString());
        }
    }

    /**
     * Method of the tests suite.
     *
     * @return Tests result.
     */
    public static Test suite()
    {
        TestSuite suite = new TestSuite();

        suite.addTest(new TestTemplate("testBegin"));

        // TESTS SET
        //suite.addTest(new TestTemplate("<testMethodName>"));
        suite.addTest(new TestTemplate("testEnd"));

        return (suite);
    }

    /**
     * Main method of the test class.
     *
     * @param args  Sets of the parameters.
     */
    public static void main(String[] args)
    {
        junit.textui.TestRunner.run(suite());
    }

    /**
     * Method to indicate the beginning of the class test.
     *
     */
    public static void testBegin()
    {
        //  To initialize the tests statement
        TestResult.getInstance().setInitiator("Template");

        _test.displayHeaderClass("Template");
        assertTrue(true);
    }

    /**
     * Method to indicate the end of the class test.
     *
     */
    public static void testEnd()
    {
        _test.displayFooterClass(null);
        assertTrue(true);

        // To display the tests statement
        _test.displayTestStatement("Template");
    }

    /**
     * This method is the pattern used to define the method test.
     *
     */
    public static void testMethod()
    {
        _test.displayHeaderMethod("testMethod");

        try
        {
            _test.displayMsg(TestUtils.NEXT + "Parameters = name : value"); // to indicate the test type
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Optional description error");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testMethod");
    }
}
